package struts.form;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;
/**
 * 将表单中的值封装到javabean中
 * @author Zzq
 *
 */
public class FullForm {

	@SuppressWarnings("rawtypes")
	public static ActionForm getForm(String beanPath, HttpServletRequest request){
		ActionForm form = null;
		
		try {
			Class clazz = Class.forName(beanPath);
			form = (ActionForm) clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for(Field f : fields){
				f.setAccessible(true);
				f.set(form, request.getParameter(f.getName()));
				f.setAccessible(false);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return form;
	}
}
